﻿namespace PublicModels.Helpers;

public static class ConvertHelper
{
    public static int[] ByteArray2IntArray(byte[] bytes)
    {
        int[] array = new int[bytes.Length];
        for (int i = 0; i < bytes.Length; i++)
            array[i] = bytes[i];
        return array;
    }

    public static GeoType ToGeometry<GeoType>(this Annotation annotation) where GeoType : Geometry => WktReader.Parse<GeoType>(annotation.FeatureInWKT);

    public static Geometry ToGeometry(this Annotation annotation) => WktReader.Parse<Geometry>(annotation.FeatureInWKT);

    public static string ToWKT(this Geometry geometry) => WktWriter.WriteToString(geometry);

    public static Annotation ToAnnotation(this Geometry geometry, int ownerID = 0) => new(geometry.ToWKT()) { OwnerID = ownerID };

    public static string ToJson(this object obj) => JsonConvert.SerializeObject(obj);

    public static T ToObject<T>(this string json) => JsonConvert.DeserializeObject<T>(json);

    public static string CleanUp(this string? text)
    {
        if (text is null) return string.Empty;
        var temp=text.Replace("<b>", " ");
        return temp.Replace("</b>", " ");
    }
}
